package order

import (
	"parking-lot-go-admin/controller"
	"parking-lot-go-admin/model"
	"parking-lot-go-admin/model/view"

	"github.com/gin-gonic/gin"
)

func Payment(c *gin.Context) {

	requestDataMap := make(map[string]interface{})
	c.ShouldBindJSON(&requestDataMap)

	where, page, pageSize := controller.WhereStructure(requestDataMap)

	//查询信息
	var xiaoqiangPaymentViewStruct view.XiaoqiangPaymentViewStruct
	var xiaoqiangPaymentViewData []view.XiaoqiangPaymentViewStruct
	model.GetModelData(
		model.Db,
		xiaoqiangPaymentViewStruct.TableName(),
		&xiaoqiangPaymentViewData,
		model.QueryOptions{
			Conditions: where,
			OrderBy:    "order_id desc",
			Page:       page,
			PageSize:   pageSize,
			Debug:      true,
		},
	)

	//数据格式化
	returnData := make([]map[string]interface{}, 0)
	for _, v := range xiaoqiangPaymentViewData {
		returnData = append(returnData, map[string]interface{}{
			"car_number":                  v.OrderCarNumber,
			"car_no_color":                v.OrderCarNoColor,
			"car_type":                    v.OrderCarType,
			"order_no":                    v.OrderOrderNo,
			"xq_order_no":                 v.OrderXiaoqiangPaymentXqOrderNo,
			"reservation_end_time_before": v.OrderXiaoqiangPaymentReservationEndTimeBefore.Format("2006-01-02 15:04:05"),
			"reservation_end_time_after":  v.OrderXiaoqiangPaymentReservationEndTimeAfter.Format("2006-01-02 15:04:05"),
			"money":                       v.Money,
		})
	}

	//总数查询
	count, _ := model.CountModelData(
		model.Db,
		xiaoqiangPaymentViewStruct.TableName(),
		model.QueryOptions{
			Conditions: where,
		},
	)

	controller.Success(c,
		map[string]interface{}{
			"list":        returnData,
			"total":       count,
			"pageSize":    pageSize,
			"currentPage": page,
		})

}
